﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2017- 匠梦科技                                         *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间:2019年5月19日 14:59:28
 *  文件描述:扩展代码
 *****************************************************************************/

using System;
using System.Collections.Generic;

namespace Util
{
    public class BagData
    {
        public List<bool> b = new List<bool>();
        public List<int> i = new List<int>();
        public List<float> f = new List<float>();
        public List<string> s = new List<string>();
    }
    public class TBag
    {
        public static TBag<T1,T2> New<T1, T2>(T1 t1,T2 t2) { return new TBag<T1,T2>(t1,t2); }
        public static TBag<T1,T2,T3> New<T1, T2, T3>(T1 t1,T2 t2,T3 t3) { return new TBag<T1,T2,T3>(t1,t2,t3); }
        public static TBag<T1,T2,T3,T4> New<T1, T2, T3, T4>(T1 t1,T2 t2,T3 t3,T4 t4) { return new TBag<T1,T2,T3,T4>(t1,t2,t3,t4); }
        public static TBag<T1,T2,T3,T4,T5> New<T1, T2, T3, T4, T5>(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5) { return new TBag<T1,T2,T3,T4,T5>(t1,t2,t3,t4,t5); }
        public static TBag<T1,T2,T3,T4,T5,T6> New<T1, T2, T3, T4, T5, T6>(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6) { return new TBag<T1,T2,T3,T4,T5,T6>(t1,t2,t3,t4,t5,t6); }
    }
    //缓存包
    //一次全部取出,用掉
    //用于单帧大量输出日志等,剥离性能检测,缓存数量充足的情况下,获取对象,无GC,无拼接数组
    public class CacheBag<T>
    {
        Func<T> NewT;
        public List<TBag<T,bool>> linked = new List<TBag<T,bool>>();
        int q = 0;
        int h = 0;
        public CacheBag(Func<T> newT)
        {
            NewT = newT;
        }
        public void Clear()
        {
            linked.Clear();
            q = 0;
            h = 0;
        }
        public T Add()
        {
            if(q < linked.Count && !linked[q].t2)
            {
                var t = linked[q];
                t.t2 = true;
                q++;
                return t.t1;
            }
            else
            {
                var t = TBag.New(NewT(),true);//唯一GC处
                linked.Add(t);//唯一拼接数组处
                h++;
                return t.t1;
            }
        }
        //当前使用的全部拿出去用掉
        public void GetAll(Action<T> action)
        {
            for(int i = 0; i < q; i++)
            {
                var t = linked[i];
                t.t2 = false;
                action(t.t1);
            }
            for(int i = 0, j = linked.Count - 1; i < h; i++, j--)
            {
                var t = linked[j];
                t.t2 = false;
                action(t.t1);
            }
            q = 0;
            h = 0;
        }
    }

    public class TBag<T1, T2>
    {
        public TBag() { }
        public T1 t1; public T2 t2;
        public TBag(T1 t1,T2 t2)
        {
            this.t1 = t1; this.t2 = t2;
        }
        public void Set(T1 t1,T2 t2)
        {
            this.t1 = t1; this.t2 = t2;
        }
    }
    public class TBag<T1, T2, T3>
    {
        public TBag() { }
        public T1 t1; public T2 t2; public T3 t3;
        public TBag(T1 t1,T2 t2,T3 t3)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3;
        }
        public void Set(T1 t1,T2 t2,T3 t3)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3;
        }
    }

    public class TBag<T1, T2, T3, T4>
    {
        public TBag() { }
        public T1 t1; public T2 t2; public T3 t3; public T4 t4;
        public TBag(T1 t1,T2 t2,T3 t3,T4 t4)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4;
        }
        public void Set(T1 t1,T2 t2,T3 t3,T4 t4)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4;
        }
    }
    public class TBag<T1, T2, T3, T4, T5>
    {
        public TBag() { }
        public T1 t1; public T2 t2; public T3 t3; public T4 t4; public T5 t5;
        public TBag(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4; this.t5 = t5;
        }
        public void Set(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4; this.t5 = t5;
        }
    }
    public class TBag<T1, T2, T3, T4, T5, T6>
    {
        public TBag() { }
        public T1 t1; public T2 t2; public T3 t3; public T4 t4; public T5 t5; public T6 t6;
        public TBag(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4; this.t5 = t5; this.t6 = t6;
        }
        public void Set(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6)
        {
            this.t1 = t1; this.t2 = t2; this.t3 = t3; this.t4 = t4; this.t5 = t5; this.t6 = t6;
        }
    }
}